<template>
  <el-dialog :visible.sync="visible" :title="title" :close-on-click-modal="false">
    <el-form ref="dataFrom" :model="dataFrom" label-position="right" style="width: 500px;">
      <el-form-item prop="modelName">
        <el-input v-model="dataFrom.modelName" placeholder="请输入修改名称" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="addSubmit()">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { insertIaIndexModel } from '@/api/setting'

export default {
  data() {
    return {
      visible: false,
      title: '新增指数分类',
      dialogStatus: 'create',
      dataFrom: {
        id: '',
        modelName: ''
      }
    }
  },
  methods: {
    init(row) {
      this.visible = true
      this.$nextTick(() => {
        this.dataFrom = {
          id: '',
          modelName: ''
        }
        if(row) {
          this.title = '修改指数分类'
          this.dialogStatus = 'update'
          this.dataFrom.id = row.id
          this.dataFrom.modelName = row.modelName
        }
      })
    },
    addSubmit() {
      insertIaIndexModel({ ...this.dataFrom }).then(res => {
        console.log('新增', res)
        this.$notify({
          message: '新增成功', 
          type: 'success',
          duration: 2000
        })
        this.$emit('openClose')
        this.visible = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
